﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace elcalc
{
    public partial class Kabeltabel : Form
    {
        DataTable dt = new DataTable();

        public Kabeltabel()
        {
            InitializeComponent();
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            using (OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Databaser\Database4.accdb"))
            {
                try
                {
                    connection.Open();

                    DataSet dataSet = new DataSet();
                    //OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Ark5 WHERE Navn LIKE '%NOIK%'", connection);
                    OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM Kabler ORDER BY Id ASC", connection);

                    adapter.Fill(dataSet);

                    dt = dataSet.Tables[0];
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    connection.Close();
                }

            }

            foreach (DataColumn col in dt.Columns)
            {
                dataGridView1.Columns.Add(col.ColumnName, col.ColumnName);
            }

            foreach (DataRow row in dt.Rows)
            {
                dataGridView1.Rows.Add(new object[] { row[0], row[1], row[2], row[3], row[4], row[5], row[6] });
            }

            int width = 28;
            foreach (DataGridViewColumn col in dataGridView1.Columns)
            {
                if (col.Visible == true)
                    width += col.Width;
            }

            this.Width = width;
        }

    }
}
